package com.rop.znyx.activity.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.rop.znyx.activity.service.SecKillSkuService;
import com.rop.znyx.common.result.Result;
import com.rop.znyx.model.activity.SecKillSku;
import com.rop.znyx.vo.activity.SecKillSkuQueryVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;
import java.util.List;

/**
 * Created with IntelliJ IDEA
 * User: Rop
 * Date: 2023/7/11
 * Time: 9:48
 * Description:
 */

@Api(tags = "秒杀sku管理")
@RestController
@RequestMapping(value = "/admin/activity/SecKillSku")
@RequiredArgsConstructor

public class SecKillSkuController {

    private final SecKillSkuService SecKillSkuService;

    /**
     * 获取分页列表
     */
    @ApiOperation(value = "获取分页列表")
    @GetMapping("{page}/{limit}")
    public Result<IPage<SecKillSku>> getList(
            @ApiParam(name = "page", value = "当前页码", required = true) @PathVariable Long page,
            @ApiParam(name = "limit", value = "每页记录数", required = true) @PathVariable Long limit,
            @ApiParam(name = "SecKillSkuQueryVo", value = "查询对象")
            SecKillSkuQueryVo SecKillSkuQueryVo) {

        Page<SecKillSku> pageParam = new Page<>(page, limit);
        IPage<SecKillSku> pageModel = SecKillSkuService.selectPage(pageParam, SecKillSkuQueryVo);
        return Result.ok(pageModel);
    }

    /**
     * 获取
     */
    @ApiOperation(value = "获取")
    @GetMapping("get/{id}")
    public Result<SecKillSku> get(@PathVariable Long id) {
        SecKillSku SecKillSku = SecKillSkuService.getById(id);
        return Result.ok(SecKillSku);
    }

    /**
     * 新增
     */
    @ApiOperation(value = "新增")
    @PostMapping("save")
    public Result<Boolean> save(@RequestBody List<SecKillSku> SecKillSkuList) {
        boolean isSuccess = SecKillSkuService.saveBatchBySkuList(SecKillSkuList);
        return isSuccess ? Result.ok() : Result.fail();
    }

    /**
     * 修改
     */
    @ApiOperation(value = "修改")
    @PutMapping("update")
    public Result<Boolean> updateById(@RequestBody SecKillSku SecKillSku) {
        boolean isSuccess = SecKillSkuService.updateById(SecKillSku);
        return isSuccess ? Result.ok() : Result.fail();
    }

    /**
     * 删除
     */
    @ApiOperation(value = "删除")
    @DeleteMapping("remove/{id}")
    public Result<Boolean> remove(@PathVariable Long id) {
        boolean isSuccess = SecKillSkuService.removeById(id);
        return isSuccess ? Result.ok() : Result.fail();
    }

    /**
     * 根据id列表删除
     */
    @ApiOperation(value = "根据id列表删除")
    @DeleteMapping("batchRemove")
    public Result<Boolean> batchRemove(@RequestBody List<Long> idList) {
        boolean isSuccess = SecKillSkuService.removeByIds(idList);
        return isSuccess ? Result.ok() : Result.fail();
    }
}
